package com.valpha.deepinandroid.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.valpha.obsutil.OBS
import java.io.File

@Composable
fun HomeView() {
    Scaffold(
        topBar = {
            TopAppBar() {
                Text(text = "1111   ")
                Text(text = "123123123")
                Text(text = "asdfasdf")
            }
        },
        bottomBar = {
            BottomAppBar {
                Text(text = "bottom")
            }
        },
        drawerContent = {
            Text(text = "第一项")
            Text(text = "sdfsd")
            Text(text = "sdfasdf")
            Text(text = "sadfasdf")
            Text(text = "123123")
            Text(text = "222222")
        }
    ) {
        Column() {
            Button(onClick = {
                var obs = OBS.getInstance()
                val filePath = "/sdcard/picture/test.png"
                Thread {
                    obs.uploadImage(File(filePath), "TestPicture2")
                    obs.closeObs()
                }.start()
            }) {
                Text(text = "上传图片")
            }

            Button(onClick = {
                var obs = OBS.getInstance()
                Thread {
                    obs.downloadImageByStream(
                        "TestPicture2",
                        "/data/data/com.valpha.deepinandroid/picture/downloadByStream.png",
                        true
                    )
                }.start()
            }) {
                Text(text = "流式下载图片")
            }

            Button(onClick = {
                var obs = OBS.getInstance()
                Thread {
                    obs.downloadImage(
                        "TestPicture2",
                        "/data/data/com.valpha.deepinandroid/picture/download.png",
                        true
                    )
                }.start()
            }) {
                Text(text = "断点续传下载图片")
            }
        }
    }

}

@Preview(showBackground = true)
@Composable
fun homePreview() {
    HomeView()
}